import 'package:flutter/cupertino.dart';
import 'package:get/get.dart';

import '../../../../../lib_baseview/lib_baseview.dart';
import '../../../../../resource/language/generated/l10n.dart';
import '../model/room_music_center_controller.dart';
import '../widget/music_item_widget.dart';

class MusicPlaylistPage extends StatelessWidget {
  final controller = Get.find<RoomMusicCenterController>();

  @override
  Widget build(BuildContext context) {
    return GetBuilder<RoomMusicCenterController>(
        id: UpdateIds.playList,
        builder: (logic) {
          // if (logic.playlist.isEmpty) {
          //   return Center(child: DFEmptyDataView());
          // }

          return Column(
            mainAxisSize: MainAxisSize.max,
            children: [
              bar(context),
              Expanded(
                child: ListView.builder(
                  itemBuilder: (c, index) {
                    bool isLast = index == logic.playlist.length - 1;
                    return Padding(
                      padding:
                          EdgeInsets.only(top: 4, bottom: isLast ? 130 : 4),
                      child: MusicItemWidget(
                          // item: logic.playlist.elementAt(index),
                          ),
                    );
                  },
                  itemCount: logic.playlist.length,
                ),
              )
            ],
          );
        });
  }

  Widget bar(BuildContext context) => Container(
        height: 44,
        padding: const EdgeInsets.symmetric(horizontal: 22),
        alignment: Alignment.center,
        child: GestureDetector(
          onTap: () {
            // JRDialog.showCommonDialog(
            //     context: context,
            //     data: TextWithHorizontalBtnDialogData(
            //         title: T.current!.tips,
            //         desc: T.current!.clear_playlist_tips,
            //         onRightBtnPress: () async {
            //           controller.clearPlaylist();
            //           return true;
            //         }));
          },
          child: Row(
            mainAxisSize: MainAxisSize.max,
            children: [
              image('ic_room_tool_music_del.png', width: 20, height: 20),
              const SizedBox(width: 10),
              Expanded(
                child: Text(T.current.clear_playlist,
                    textAlign: TextAlign.start,
                    style: const TextStyle(
                        color: Color(0xFF666666), fontSize: 13)),
              ),
              Text(T.current.total_few_song(controller.playlist.length),
                  textAlign: TextAlign.start,
                  style:
                      const TextStyle(color: Color(0xFF666666), fontSize: 13)),
            ],
          ),
        ),
      );
}
